package com.permission.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.solution.framework.model.BaseBean;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;

/**
 * Created with generator tools.
 * User: sunguangzhu
 * DateTime:2014-05-07 01:19:05
 */
@Entity
@Table(name = "t_per_dept")
public class PerDept extends BaseBean implements java.io.Serializable {

    /**
     * 名称
     */
    private java.lang.String name;

    /**
     * 上级部门
     */
    private com.permission.model.PerDept parent;

    /**
     * 用户集合
     */
    private java.util.Set<com.permission.model.PerUser> perUsers;

    /**
     * default constructor
     */
    public PerDept() {
    }

    /**
     * full constructor
     *
     * @param name
     * @param parent
     * @param perUsers
     */
    public PerDept(java.lang.String name, com.permission.model.PerDept parent, java.util.Set<com.permission.model.PerUser> perUsers) {
        this.name = name;
        this.parent = parent;
        this.perUsers = perUsers;
    }

    /**
     * getter
     */
    @Column
    public java.lang.String getName() {
        return this.name;
    }

    /**
     * setter
     *
     * @param name
     */
    public void setName(java.lang.String name) {
        this.name = name;
    }

    /**
     * getter
     */
    @JsonManagedReference
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @ForeignKey(name = "fk_perdept_parent")
    public com.permission.model.PerDept getParent() {
        return this.parent;
    }

    /**
     * setter
     *
     * @param parent
     */
    public void setParent(com.permission.model.PerDept parent) {
        this.parent = parent;
    }

    /**
     * getter
     */
    @JsonBackReference
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "perDept")
    public java.util.Set<com.permission.model.PerUser> getPerUsers() {
        return this.perUsers;
    }

    /**
     * setter
     *
     * @param perUsers
     */
    public void setPerUsers(java.util.Set<com.permission.model.PerUser> perUsers) {
        this.perUsers = perUsers;
    }

}
